<template>
	<view class="container">
		<view class="top">
			<view class="top-item">
				申请事项
			</view>
			<view class="top-item">
				金额
			</view>
			<view class="top-item">
				状态
			</view>
			<view class="top-item">
				日期
			</view>
		</view>
		<view v-for="(item, index) in list" :key="index" class="item">
			<view class="col1">
				{{item.content}}
			</view>
			<view class="col1">
				{{item.amount}}
			</view>
			<view v-if="item.audited === 1 && item.loaned !== true">
				已审核
			</view>
			<view v-else-if="item.audited === 1 && item.loaned === true">
				已发放
			</view>
			<view v-else class="col1">
				未审核
			</view>
			<view class="col1">
				{{item.submitDate}}
			</view>
		</view>
		
		<u-loadmore :status="status" />
	</view>
</template>

<script>
	import { getImprestList } from '@/api/common.js'
	import {
		mapState
	} from 'vuex';
	export default {
		computed: {
			...mapState({
				tchInfo: state => state.user.tchInfo,
			}),
		},
		data() {
			return {
				list: [],
				status: 'loadmore',
				page: -1,
			}
		},
		onLoad() {
			this.getList(this.page);
		},
		methods: {
			getList(page) {
				getImprestList({pageNum: page + 1, pageSize: 10, createdBy: this.tchInfo.staff.id}).then(res => {
					if (res.data.last) {
						this.status = 'nomore';
					}
					this.page = res.data.number;
					if (this.page === 0) {
						this.list = res.data.content;
					} else {
						this.list = this.list.concat(res.data.content);
					}
				})
			},
			
			loadMore() {
				if (this.status === 'nomore') {
					return;
				}
				this.status = 'loading';
				this.getList(this.page);
			},
			
			onReachBottom() {
				this.loadMore();
			},
		}
	}
</script>

<style lang="scss">
	.container{
		display: flex;
		flex-direction: column;
		padding-left: 30rpx;
		padding-right: 30rpx;
		
		.top{
			display: flex;
			flex-direction: row;
			width: 100%;
			padding: 15rpx;
			.top-item{
				width: 25%;
				display: flex;
				justify-content: center;
				align-items: center;
				font-size: 30rpx;
				font-weight: bold;
			}
		}
	}
	.item{
		display: flex;
		flex-direction: row;
		justify-content: space-around;
		box-shadow: 0px 8rpx 0px 0px rgba(40,168,113,0.15);
		border-radius: 12rpx;
		padding: 15rpx;
		margin-top: 10rpx;
		margin-bottom: 10rpx;
		width: 100%;
		
		.col1{
			width: 25%;
			display: flex;
			justify-content: center;
			align-items: center;
		}
	}
</style>
